<template>
  <div style="width:100%;overflow:hidden">
    <div class="back">
      <img :src="data.backgroundUrl" alt="" />
      <div class="button" @click="getBack()">
        <span class="iconfont icon-arrow-left-bold"></span>
        返回
      </div>
      <div class="top">
        <div class="img">
          <img :src="data.avatarUrl" alt="" />
        </div>
        <div class="detail">
          <h1>{{ data.nickname }}</h1>
          <h2>Lv{{ level }}</h2>
          <hr />
          <div class="amount">
            <ul>
              <li>
                <span>{{ data.eventCount }}</span
                ><br />动态
              </li>
              <router-link tag="li" :to="'/follow/followlist?id='+uid">
                <span>{{ data.newFollows }}</span
                ><br />关注
              </router-link>
              <li>
                <span>{{ data.followeds }}</span
                ><br />粉丝
              </li>
            </ul>
            <br />
            <br />
            <br />
            <h3>加入网易云大军已经:{{ createDays }}天</h3>
          </div>
        </div>
      </div>
    </div>

    <div class="createlist">
      <h4>我创建的歌单({{ data.playlistCount }})</h4>
      <div class="songlist">
        <ul>
            <router-link tag="li" to="/playHistory/playHistory">
            <img :src="picture1" alt="">
            <p>我的最近播放</p>
            <p>最近播放{{ recent.length }}首</p>
            </router-link>
          <li>
            <img :src="picture2" alt="" />
            <p>我喜欢的音乐</p>
            <p>{{ amount1 }}首</p>
          </li>
          <li>
            <img :src="picture3" alt="" />
            <p>{{ data.nickname }}的年度歌单</p>
            <p>{{ amount2 }}首</p>
          </li>
        </ul>
      </div>
    </div>


    <div class="maybe">
      <h2>猜你喜欢</h2>
      <div class="pro">
              <ul>
        <li v-for="(item,index) in recent.slice(0, 10)"  :key="index">
          <img :src="item.song.al.picUrl" alt="">
          <p>{{item.song.al.name}}</p>
        </li>
      </ul>
      </div>
    </div>

    <!-- 退出登录 -->
    <div class="shutdown" @click="shutdown()">
      退出登录
    </div>

    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>


  </div>
</template>


<script>
import {
  getUserDetail,
  getUserSongs,
  getPlayHistory,
} from "../../api/base";

export default {
  data() {
    return {
      uid: this.$store.state.userId,
      uid2:this.$store.state.userId2,
      data: "",
      level: "",
      createDays: "",
      recent: "",
      picture1: "",
      picture2: "",
      picture3: "",
      amount1: "",
      amount2: "",
      follows: "",
      followsId:'',
      flag:true,
    };
  },
  methods: {
      getThisId(item){
      // console.log(item.userId)
      this.followsId = item.userId
      console.log(this.followsId)
    },
    getAllId() {
      if(this.uid != '' && this.uid2 == ''){
        getUserDetail({ uid: this.uid }).then((data) => {
        // console.log(data);
        this.level = data.level;
        this.createDays = data.createDays;
        this.data = data.profile;
      });
      getUserSongs({ uid: this.uid }).then((data1) => {
        // console.log(data1, "data1");
        this.picture2 = data1.playlist[0].coverImgUrl;
        this.picture3 = data1.playlist[1].coverImgUrl;
        this.amount1 = data1.playlist[0].trackCount;
        this.amount2 = data1.playlist[1].trackCount;
      });
      getPlayHistory({ uid: this.uid, type: 1 }).then((data2) => {
        console.log(data2,"data2");
        this.recent = data2.weekData;
        this.picture1 = data2.weekData[0].song.al.picUrl;
      });
      }else{
              getUserDetail({ uid: this.uid2 }).then((data) => {
        // console.log(data);
        this.level = data.level;
        this.createDays = data.createDays;
        this.data = data.profile;
      });
      getUserSongs({ uid: this.uid2 }).then((data1) => {
        // console.log(data1, "data1");
        this.picture2 = data1.playlist[0].coverImgUrl;
        this.picture3 = data1.playlist[1].coverImgUrl;
        this.amount1 = data1.playlist[0].trackCount;
        this.amount2 = data1.playlist[1].trackCount;
      });
      getPlayHistory({ uid: this.uid2, type: 1 }).then((data2) => {
        // console.log(data2,"data2");
        this.recent = data2.weekData;
        this.picture1 = data2.weekData[0].song.al.picUrl;
      });
      }
    },
    getBack(){
      this.$router.push("/recommend");
      this.$store.commit("saveUserId2",'');
    },
    shutdown(){
      console.log(111)
      this.$router.push("/login");
      this.$store.commit("outLogin");
      this.$store.commit("musicDatafun",'');
      this.$store.commit("saveUserId",'');
      //  console.log(this.$store.state.login)
      //  this.$store.state.login = !this.$store.state.login
    }
  },
  created() {
    this.getAllId();
  }
};
</script>

<style lang="less" scoped>
.back {
  width: 100%;
  height: 600px;
  position: relative;
  img {
    width: 100%;
    height: 100%;
  }
  .button {
    color: #fff;
    width: 150px;
    height: 40px;
    line-height: 40px;
    font-size: 35px;
    // background: #000;
    color: #e5e5e5;
    margin: 10px 0;
    position: absolute;
    top: 0;
    left: 0;
    span {
      display: inline-block;
      font-size: 40px;
      vertical-align: top;
    }
  }
  .top {
    width: 100%;
    display: flex;
    position: absolute;
    left: 0;
    bottom: 0;
    .img {
      margin: 20px 10px;
      flex: 0 0 200px;
      img {
        border-radius: 50%;
        border: 1px solid #e5e5e5;
      }
    }
    .detail {
      flex: 1;
      margin-left: 20px;
      h1 {
        margin: 10px 0;
        color: #f0f0f0;
      }
      h2 {
        font-size: 20px;
        background: #f0f0f0;
        width: 50px;
        height: 30px;
        line-height: 30px;
        border-radius: 12px;
        text-align: center;
        margin-bottom: 10px;
      }
      .amount {
        ul {
          li {
            text-align: center;
            width: 50px;
            color: #f0f0f0;
            float: left;
            border-left: 1px solid #e6e6e6;
            padding: 0 20px;
            &:nth-child(1) {
              border-left: none;
            }
          }
        }
        h3 {
          color: #f0f0f0;
        }
      }
    }
  }
}

.createlist {
  width: 100%;
  height: 100%;
  margin-top: 20px;
  h4 {
    color: #373737;
    font-size: 30px;
  }
  .songlist {
    ul {
      display: flex;
      margin-top: 15px;
      li {
        flex: 1;
        margin-left: 15px;
        img {
          width: 150px;
          height: 150px;
          border-radius: 5px;
        }
        p {
          text-align: left;
          color: #000000;
          &:nth-child(3) {
            color: #9f9f9f;
          }
        }
      }
    }
  }
}

.shutdown{
  width: 96%;
  height: 50px;
  line-height: 50px;
  // border: 1px solid #000;
  border-radius: 5px;
  background-color: #00A2E8;
  margin: 50px auto 0 auto;
  text-align: center;
  padding:10px 0;
  color: #ffffff;
}

.maybe{
  margin-top: 50px;

  background-color: #F2F2F2;
  h2{
    margin-bottom: 30px;
  }
  .pro{
      overflow: scroll;
  ul{
    width: 1650px;
    height: 180px;
    overflow: hidden;
    li{
      width: 100px;
      height: 150px;
      float: left;
      margin: 0 0 0 15px;
      display: table;
      img{
        width: 100px;
        height: 100px;
        vertical-align:middle;
        border-radius: 50%;
      }
      p{
        margin-top: 10px;
        width: 150px;
        height: 60px;
        overflow: hidden;
      }
    }
  }
  }


}
</style>